<?php

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;

class User extends Model
{
    //首页添加用户校验
    //软删除
    use SoftDelete;
    //后台添加校验4
    public function add($data){
        $validate=new \app\common\validate\User();
        if(!$validate->scene('add')->check($data)){
            return $validate->getError();
        }else{
            $result=$this->allowField(true)->save($data);
            if($result) {
                return 1;
            }else{
                return "用户添加失败";
            }
        }
    }
    //后台编辑校验
    public function edit($data){
        $validate=new \app\common\validate\User();
        if(!$validate->scene('edit')->check($data)){
            return $validate->getError();
        }else{
            $userInfo=$this->find($data['id']);
            $userInfo->uname=$data['uname'];
            $userInfo->age=$data['age'];
            $userInfo->sex=$data['sex'];
            $userInfo->address=$data['address'];
            $userInfo->tel=$data['tel'];
            $result=$userInfo->save();
            if($result) {
                return 1;
            }else{
                return "用户修改失败";
            }
        }
    }
}
